package com.zero.manage.web.components.dao;

import com.zero.manage.web.components.base.BaseDao;
import com.zero.manage.web.components.entity.rbac.SysPowerEntity;
import io.gitee.zerowsh.enums.ToolEnums;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface SysPowerDao extends BaseDao<SysPowerEntity, String> {
    @Query(value = "select sp.url from SysPowerEntity sp where sp.type=?1")
    List<String> getUrlByType(ToolEnums.PowerTypeEnums type);

    @Modifying
    @Query(value = "update sys_power  set parent_ids=replace(parent_ids,?1,?2) where parent_ids like %?3%", nativeQuery = true)
    int replaceParentIds(String oldParentId, String parentId, String id);

    @Modifying
    @Query(value = "update sys_power  set parent_ids=?1+parent_ids where parent_ids like %?2%", nativeQuery = true)
    int appendBeforeParentIds(String parentId, String id);
}
